package com.yu.rabbitmq.one;

import com.rabbitmq.client.Channel;
import com.yu.rabbitmq.utils.RabbitMqUnits;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

public class Task01 {
    private static String QUEUE_NAME = "hello";

    public static void main(String[] args) {
        try (Channel channel = RabbitMqUnits.getChannel()) {
            channel.queueDeclare(QUEUE_NAME,false,false,false,null);
            Scanner scanner = new Scanner(System.in);
            while (scanner.hasNext()){
                String next = scanner.next();
                channel.basicPublish("",QUEUE_NAME,null,next.getBytes());
                System.out.println("消息发送完成");
            }


        } catch (TimeoutException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
